﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using LegSec.NugetThirdPartyLicenseFileGenerator;
using NUnit.Framework;

namespace LEgSec.NugetThirdPartyLicenseFileGenerator.Test
{
    [TestFixture]
    public class LicenseFileGeneratorIntegrationTest
    {
        private string TestPackageLocation;
        private const string OUTPUT_FILE_NAME = "TestOutput.xml";
        private LicenseFileGenerator LicenseFileGenerator;
        private string IGNORED_NAMESPACE = "";

        [Test]
        public void Test()
        {
            TestPackageLocation = Path.Combine(System.Environment.CurrentDirectory, "..\\..\\TestPackages");
            LicenseFileGenerator = new LicenseFileGenerator(TestPackageLocation, TestPackageLocation, OUTPUT_FILE_NAME, IGNORED_NAMESPACE);
            LicenseFileGenerator.Generate();
            AssertOutputCreated();
        }

        private void AssertOutputCreated()
        {
            var TestPackageDirectory = new DirectoryInfo(TestPackageLocation);
            Assert.True(TestPackageDirectory.GetFiles("*.xml").Length == 1, "Wrong number of xml files");
            Assert.True(TestPackageDirectory.GetFiles("*.xml")[0].FullName.EndsWith(OUTPUT_FILE_NAME), "Directory did not contain correct files");
            Assert.False(TestPackageDirectory.GetDirectories().Contains(new DirectoryInfo("nuspec")), "Nuspec directory was not removed");
        }
    }
}
